// pages/notice/notice.js
var util = require('../../utils/util.js');
Page({
    data: {
        limit: 10,
        offset: 0,
        seconds: [],
        lists: [],
        lengths: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function() {
        this.getList(this.data.offset, this.data.limit);
    },
    onshow: function() {
        this.getList(this.data.offset, this.data.limit);
    },
    yulan: function(e) {
        let imgs = [];
        let currentUrl = e.currentTarget.dataset.url;
        let currentUrls = e.currentTarget.dataset.urls;
        for (let i = 0; i < currentUrls.length; i++) {
            imgs.push('https://bwgxcxapitest.taoomall.com' + currentUrls[i])
        }
        wx.previewImage({
            current: imgs[currentUrl], // 当前显示图片的http链接
            urls: imgs // 需要预览的图片http链接列表
        })
    },
    // 获取消息
    getList: function(offset, limit) {
        var arrs = {
            offset: offset,
            limit: limit,
        }
        util.myrequest(arrs, '/report/lists', 'GET', (res) => {
            if (res.result) {
                this.setData({
                    lengths: res.datas.length,
                    offset: this.data.offset + this.data.limit,
                })
                let arr = this.data.seconds.concat(res.datas);
                this.setData({
                    seconds: arr,
                })
            }
        })
    },
    // 刷新页面
    onReachBottom: function() {
        if (this.data.lengths > 0) {
            this.getList(this.data.offset, this.data.limit)
        } else {}
    },
    // /下拉刷新
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading() //在标题栏中显示加载
            //模拟加载
        var arrs = {
            offset: 0,
            limit: 10,
        }
        util.myrequest(arrs, '/report/lists', 'GET', (res) => {
            if (res.result) {
                this.setData({
                    seconds: [],
                    lengths: res.datas.length,
                    offset: 10,
                })
                wx.stopPullDownRefresh() //停止下拉刷新
                this.setData({
                    seconds: res.datas,
                })
            }
        })
        setTimeout(function() {
            wx.hideNavigationBarLoading() //完成停止加载
            wx.stopPullDownRefresh() //停止下拉刷新
        }, 1500);

    },
})